class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        string res=strs[0];
        int minLength=INT_MAX;
        for(int i=0;i<strs.size();i++){
            if(strs[i].empty()) return "";
            for(int j=0;j<strs[i].length();j++){
                int tmp=strs[i].length();
                if(res[j]!=strs[i][j]){
                    res.erase(j);
                    break;
                }
                if(tmp<minLength) minLength=tmp;
            }
        }
        res=res.substr(0,minLength);
        return res;
    }
};
